#include "stdafx.h"
#include "Configure.h"
#include <fstream>
#include <boost/algorithm/string.hpp>

Configure * Configure::configure = NULL;
Configure::Configure(void)
{
	initial();
}
 

Configure::~Configure(void)
{
}
Configure* Configure::getInstance(void)
{
	if(configure==NULL)
	{
		configure = new Configure();
	}
	return configure;
}
void Configure::initial()
{
    std::cout<<"reading configure files"<<std::endl;
	this->configureFilePath = "./configure/bstream.conf";
	std::ifstream fin(configureFilePath.c_str());
	std::string s;
	while(getline(fin,s))
	{
		//std::cout<<s<<std::endl;
		std::string key = s.substr(0,s.find('='));
		boost::trim(key);
		std::string value = s.substr(s.find('=')+1,s.length());
		boost::trim(value);
		//std::cout<<key<<std::endl;
		//std::cout<<value<<std::endl;
		this->configuration.insert(make_pair(key,value));
	}
}

std::string Configure::getConfigureFilePath(void)
{
	return this->configureFilePath;
}
std::string Configure::getConfigureValue(std::string key)
{
	boost::associative_property_map< std::map<std::string, std::string> >
		configuration(this->configuration);
	return configuration[key];

}
std::map<std::string, std::string> Configure::getAllConfigureValue(void)
{
	return this->configuration;
}
